import React, { Component } from 'react'
import axios from 'axios'
import store from './store'
import Demo from './components/Demo'
export default class App extends Component {
  constructor(props) {
    super(props)
    console.log(store.getState());
  }
  state = {
    userName: '',
    passWord: ''
  }
  handlechange(val, e) {
    this.setState({
      [val]: e.target.value
    })
  }
  render() {
    console.log(this.store);
    return (
      <div>
        账号<input type="text"
          value={this.state.userName}
          onChange={this.handlechange.bind(this, 'userName')}
        /><br />
        密码<input type="password"
          value={this.state.passWord}
          onChange={this.handlechange.bind(this, 'passWord')}
        />
        <button onClick={(params) => {
          axios.get('http://s.linweiqin.com/api/s/loginCheck',
            {
              params: {
                username: this.state.userName,
                password: this.state.passWord
              }
            }).then(res => {
              console.log(res);
              store.dispatch({
                type: 'GetTooken',
                payload: {
                  userInfo:res.data
                }
              })
            })
        }
        }>登陆</button>
        <Demo></Demo>
      </div >
    )
  }
}
